<%#=
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
%>

<% locked_for_user = subfolder && subfolder.locked_for_user? %>
<% locked = subfolder && subfolder.locked? %>    

<td class="check"><%= check_box_tag(name, id, false, 
  :title => l(:title_check_for_zip_download_or_email)) %></td>
<td class="title">                
  <%= link_to(h(title),          
    dmsf_folder_path(:id => project, :folder_id => subfolder),
    :class => 'icon icon-folder') %>
  <% if link %>
    <div class="filename" title="<%= l(:label_target_folder)%>"><%= link.path %></div>
  <% else %>
    <div class="filename" title="<%= l(:title_items)%>">[<%= subfolder.items %>]</div>
  <% end %>
</td>            
<td class="size"></td>
<td class="modified"><%= format_time(subfolder.modified) if subfolder %>                
  <% if locked_for_user %>
    <% if subfolder.lock.reverse[0].user %>            
      <%= link_to(image_tag(link ? 'locked_gray.png' : 'locked.png', :plugin => 'redmine_dmsf'),
        user_path(subfolder.lock.reverse[0].user),
        :title => l(:title_locked_by_user, :user => subfolder.lock.reverse[0].user)) %>
    <% else %>            
      <%= content_tag(:span, image_tag(link ? 'locked_gray.png' : 'locked.png', :plugin => 'redmine_dmsf'), 
        :title => l(:notice_account_unknown_email)) %>
    <% end %>
  <% elsif locked %>          
    <%= content_tag(:span, image_tag(link ? 'lockedbycurrent_gray.png' : 'lockedbycurrent.png', :plugin => 'redmine_dmsf'), 
      :title => l(:title_locked_by_you)) %>
  <% end %>        
</td>
<td class="version"></td>
<td class="workflow"></td>
<td class="author"><%= h(subfolder.user) if subfolder %></td>
<td class="buttons">
  <% if @folder_manipulation_allowed %>
    <% unless locked %>
     <%= link_to(image_tag('edit.png'),
        edit_dmsf_path(:id => project, :folder_id => subfolder),
        :title => l(:link_edit, :title => subfolder ? h(subfolder.title) : project.name)) %>
      <% if subfolder %>
        <%= link_to(image_tag('lock.png', :plugin => 'redmine_dmsf'),
          lock_dmsf_path(:id => project, :folder_id => subfolder),
          :title => l(:title_lock_file)) %>
      <% else %>
        <span class="icon"></span>
      <% end %>
      <% if (subfolder && subfolder.notification) || (!subfolder && project.dmsf_notification) %>            
        <%= link_to(image_tag('notify.png', :plugin => 'redmine_dmsf'),
          notify_deactivate_dmsf_path(:id => project, :folder_id => subfolder),
          :title => l(:title_notifications_active_deactivate)) %>
      <% else %>            
        <%= link_to(image_tag('notifynot.png', :plugin => 'redmine_dmsf'),
          notify_activate_dmsf_path(:id => project, :folder_id => subfolder),
          :title => l(:title_notifications_not_active_activate)) %>
      <% end %>
      <% if link %>
        <%= link_to(image_tag('delete.png'),
          dmsf_link_path(link),
          :data => {:confirm => l(:text_are_you_sure)},
          :method => :delete,
          :title => l(:title_delete)) %>                       
      <% else %>
        <%= link_to(image_tag('delete.png'),
          delete_dmsf_path(:id => project, :folder_id => subfolder),
          :data => {:confirm => l(:text_are_you_sure)},            
          :title => l(:title_delete)) %>             
      <% end %>    
    <% else %>       
      <span class="icon"></span>
      <% if (!locked_for_user || @force_file_unlock_allowed) && subfolder.unlockable? %>
        <%= link_to(image_tag('unlock.png', :plugin => 'redmine_dmsf'),
          unlock_dmsf_path(:id => project, :folder_id => subfolder),
          :title => l(:title_unlock_file)) %>        
      <% end %>        
    <% end %>                                                                                                                                                                       
  <% end %>
</td>
<td class="invisible">0</td>
<td class="invisible">0</td>
<td class="invisible"><%= subfolder.modified.to_i if subfolder %></td>
<td class="invisible">0</td>